﻿using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using MyFloridaHouse.libSvOpenDistricts.DataService;

namespace MyFloridaHouse.libSvOpenDistricts.Criteria
{
    public class CriteriaDatasetManager
    {

        //*********************  Static  ********************************************
        private static ServiceDAL _serviceDAL;

        private static CriteriaDatasetManager _criteriaDatasetManagerInstance;
        public static CriteriaDatasetManager criteriaDatasetManagerInstance
        {
            get { return _criteriaDatasetManagerInstance; }
        }


        public static List<string> GetDatasetNames()
        {
            // need to change this to read from isolated storage, local storage, or blob storage

            List<string> resultList = new List<string>();

            resultList.Add("Census Only");
            resultList.Add("Census, ACS and DMV");
            resultList.Add("Census, ACS, Elections and DMV");

            return resultList;
        }

        public static DataDictionaryIDList GetActiveDictionaryIDs()
        {
            return _criteriaDatasetManagerInstance.FindActiveDictionaryIDs();
        }

        public static void UpdateSubscriberDisplayCriteriaIndex(string subscriberName, int displayCriteriaIndex)
        {
            _criteriaDatasetManagerInstance.UpdateSubscriberDisplayCriteria(subscriberName, displayCriteriaIndex);
        }

        public static ObservableCollection<CriteriaDatasetDTO> Subscribe(string criteriaDatasetName, string subscriberName)
        {
            ObservableCollection<CriteriaDatasetDTO> datasetCriteriaList = CriteriaDatasetManager.GetCriteriaDataset(criteriaDatasetName);
            criteriaDatasetManagerInstance.UpdateSubscriber(subscriberName, datasetCriteriaList);
            return datasetCriteriaList;
        }

        public static ObservableCollection<CriteriaDatasetDTO> GetCriteriaDataset(string criteriaDatasetName)
        {
            ObservableCollection<CriteriaDatasetDTO> datasetCriteriaList = new ObservableCollection<CriteriaDatasetDTO>();

            if (criteriaDatasetName == "Census Only")
            {
                datasetCriteriaList = AddCriteria_CensusPopulation(datasetCriteriaList);
                datasetCriteriaList = AddCriteria_ACSPopulationCaribean(datasetCriteriaList);
            }

            else if (criteriaDatasetName == "Census, ACS and DMV")
            {
                datasetCriteriaList = AddCriteria_CensusPopulation(datasetCriteriaList);
                datasetCriteriaList = AddCriteria_ACSPopulationCaribean(datasetCriteriaList);

                datasetCriteriaList = AddCriteria_CensusLanguage(datasetCriteriaList);
                datasetCriteriaList = AddCriteria_ACSHispanic(datasetCriteriaList);
                datasetCriteriaList = AddCriteria_CensusEducation(datasetCriteriaList);
                datasetCriteriaList = AddCriteria_CensusIncome(datasetCriteriaList);
                datasetCriteriaList = AddCriteria_CensusHousing(datasetCriteriaList);
                datasetCriteriaList = AddCriteria_CensusVeterans(datasetCriteriaList);
                datasetCriteriaList = AddCriteria_CensusTransportation(datasetCriteriaList);
                datasetCriteriaList = AddCriteria_CensusWorkType(datasetCriteriaList);

                datasetCriteriaList = AddCriteria_DMV_VAP_Diff_Total(datasetCriteriaList);
                datasetCriteriaList = AddCriteria_DMV_VAP_Diff_Black(datasetCriteriaList);
                datasetCriteriaList = AddCriteria_DMV_VAP_Diff_Hispanic(datasetCriteriaList);
                datasetCriteriaList = AddCriteria_DMV_VAP_Diff_Asian(datasetCriteriaList);
            }

            else if (criteriaDatasetName == "Census, ACS, Elections and DMV")
            {
                datasetCriteriaList = AddCriteria_CensusPopulation(datasetCriteriaList);
                datasetCriteriaList = AddCriteria_ACSPopulationCaribean(datasetCriteriaList);

                datasetCriteriaList = AddCriteria_CensusLanguage(datasetCriteriaList);
                datasetCriteriaList = AddCriteria_ACSHispanic(datasetCriteriaList);
                datasetCriteriaList = AddCriteria_CensusEducation(datasetCriteriaList);
                datasetCriteriaList = AddCriteria_CensusIncome(datasetCriteriaList);
                datasetCriteriaList = AddCriteria_CensusHousing(datasetCriteriaList);
                datasetCriteriaList = AddCriteria_CensusVeterans(datasetCriteriaList);
                datasetCriteriaList = AddCriteria_CensusTransportation(datasetCriteriaList);
                datasetCriteriaList = AddCriteria_CensusWorkType(datasetCriteriaList);

                datasetCriteriaList = AddCriteria_ElectionsGeneral(datasetCriteriaList);
                datasetCriteriaList = AddCriteria_ElectionsVoterRegistration(datasetCriteriaList);
                datasetCriteriaList = AddCriteria_ElectionsVoted(datasetCriteriaList);

                datasetCriteriaList = AddCriteria_DMV_VAP_Diff_Total(datasetCriteriaList);
                datasetCriteriaList = AddCriteria_DMV_VAP_Diff_Black(datasetCriteriaList);
                datasetCriteriaList = AddCriteria_DMV_VAP_Diff_Hispanic(datasetCriteriaList);
                datasetCriteriaList = AddCriteria_DMV_VAP_Diff_Asian(datasetCriteriaList);

            
            }
            
            return datasetCriteriaList;
        }



        public static ObservableCollection<CriteriaDatasetDTO> AddCriteria_CensusPopulation(ObservableCollection<CriteriaDatasetDTO> datasetCriteriaList)
        {
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForTotal("TPOP10", "TPOP10", "Total Population (2010 Census)", false, 0, 148077));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("AllBlkPop10", "%AllBlkPop10", "Total Black Population, Including All Multirace Who Included \"Black\" Among Their Responses, Divided by Total Population (2010 Census)", false, 0, 3105, 0, 148077));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("AllBlkVAP10", "%AllBlkVAP10", "Total Black Voting Age Population, Including All Multirace Who Included \"Black\" Among Their Responses, Divided by Total Voting Age Population (2010 Census)", false, 0, 3113, 0, 148227));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("AllHispPop10", "%AllHispPop10", "Total Hispanic Population, Including Hispanic Black, Divided by Total Population (2010 Census)", false, 0, 3106, 0, 148077));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("AllHispVAP10", "%AllHispVAP10", "Total Hispanic Voting Age Population, Including Hispanic Black,Divided by Total Voting Age Population (2010 Census)", false, 0, 3114, 0, 148227));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("SRWPop10", "%SRWPop10", "Single-Race Non-Hispanic White Population Divided by Total Population (2010 Census)", false, 0, 3101, 0, 148077));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("SRWVAP10", "%SRWVAP10", "Single-Race Non-Hispanic White Voting Age Population Divided by Total Voting Age Population (2010 Census)", false, 0, 3109, 0, 148227));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("NHBPop10", "%NHBPop10", "Non-Hispanic Black Population, Including Multirace, Divided by Total Population (2010 Census)", false, 0, 3102, 0, 148077));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("NHBVAP10", "%NHBVAP10", "Non-Hispanic Black Voting Age Population, Including Multirace, Divided by Total Voting Age Population (2010 Census)", false, 0, 3110, 0, 148227));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("HBPop10", "%HBPop10", "Hispanic Black Population, Including Multirace, Divided by Total Population (2010 Census)", false, 0, 3103, 0, 148077));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("HBVAP10", "%HBVAP10", "Hispanic Black Voting Age Population, Including Multirace, Divided by Total Voting Age Population (2010 Census)", false, 0, 3111, 0, 148227));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("HxBPop10", "%HxBPop10", "Hispanic Population, Excluding Hispanic Black, Divided by Total Population (2010 Census)", false, 0, 3104, 0, 148077));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("HxBVAP10", "%HxBVAP10", "Hispanic Voting Age Population, Excluding Hispanic Black, Divided by Total Voting Age Population (2010 Census)", false, 0, 3112, 0, 148227));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("OthPop10", "%OthPop10", "Population of All Other Combined (Excludes All Single-Race White, All Single-Race Black, All Multirace Black, and All Hispanic Population) Divided by Total Population (2010 Census)", false, 0, 3107, 0, 148077));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("OthVAP10", "%OthVAP10", "Voting Age Population of All Other Combined (Excludes All Single-Race White, All Single-Race Black, All Multirace Black, and All Hispanic Population) Divided by Total Voting Age Population (2010 Census)", false, 0, 3115, 0, 148227));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("AsianPOP10", "%AsianPOP10", "percent Asian Population Divided by Total Population (2010 Census)", false, 0, 148082, 0, 148077));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("AsianVAP10", "%AsianVAP10", "Percent of Asian Voting Age Population Divided by Total Voting Age Population (2010 Census)", false, 0, 148232, 0, 148227));
            return datasetCriteriaList;
        }

        public static ObservableCollection<CriteriaDatasetDTO> AddCriteria_ACSPopulationCaribean(ObservableCollection<CriteriaDatasetDTO> datasetCriteriaList)
        {
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("WIndiesPOPACS", "%WIndiesPOPACS", "percent West Indies Population Divided by Total Population (2009 5yr Census ACS)", false, 0, 152347, 0, 151834));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("HaitianPOPACS", "%HaitianPOPACS", "percent Haitian Population Divided by Total Population (2009 5yr Census ACS)", false, 0, 152354, 0, 151834));
            return datasetCriteriaList;
        }

        public static ObservableCollection<CriteriaDatasetDTO> AddCriteria_DMV_VAP_Diff_Total(ObservableCollection<CriteriaDatasetDTO> datasetCriteriaList)
        {
            //VAP - DMV Compared Post PL Release
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForTotal("TotVAP10", "TotVAP10", "Total Census Voting Age Population VAP", false, 0, 148227));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForTotal("DMVTot10", "DMVTot10", "Total licensed Drivers and ID cards over 18yrs old Without Allocated", false, 0, 3001));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForTotal("DMVNewTot10", "DMVNewTot10", "Total licensed Drivers and ID cards over 18yrs old With Allocated", false, 0, 3009));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForTotalDifference("DifDMV-VAP", "DifDMV-VAP", "The Difference between Licensed Drivers and Census Voting Age Population for 2010", false, 0, 3009, 0, 148227));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForTotalDifferenceRelativeMagnitude("RelMagDifDMV-VAP", "RelMagDifDMV-VAP", "The Relative Magnitude of the Difference between Licensed Drivers and Census Voting Age Population for 2010", false, 0, 3009, 0, 148227));
            return datasetCriteriaList;
        }

        public static ObservableCollection<CriteriaDatasetDTO> AddCriteria_DMV_VAP_Diff_Black(ObservableCollection<CriteriaDatasetDTO> datasetCriteriaList)
        {
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForTotal("BlackDMV10", "BlackDMV10", "Total Black licensed Drivers and ID cards over 18yrs old", false, 0, 3003));
            //datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForTotal("BlackVAP10", "BlackVAP10", "Total Census Black Voting Age Population VAP", false, 0, 148230));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForTotalDifference("DifBDMV-BVAP", "DifBDMV-BVAP", "The Difference between Black Licensed Drivers and Census Voting Age Population for 2010", false, 0, 3003, 0, 3113));
            return datasetCriteriaList;
        }

        public static ObservableCollection<CriteriaDatasetDTO> AddCriteria_DMV_VAP_Diff_Hispanic(ObservableCollection<CriteriaDatasetDTO> datasetCriteriaList)
        {
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForTotal("HispDMV10", "HispDMV10", "Total Hispanic licensed Drivers and ID cards over 18yrs old", false, 0, 3004));
            //datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForTotal("HispVAP10", "HispVAP10", "Total Census Hispanic Voting Age Population VAP", false, 0, 148305));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForTotalDifference("DifHDMV-HVAP", "DifHDMV-HVAP", "The Differance between Hispanic Licensed Drivers and Census Voting Age Population for 2010", false, 0, 3004, 0, 3114));
            return datasetCriteriaList;
        }

        public static ObservableCollection<CriteriaDatasetDTO> AddCriteria_DMV_VAP_Diff_Asian(ObservableCollection<CriteriaDatasetDTO> datasetCriteriaList)
        {
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForTotal("AsianVAP10", "AsianVAP10", "Total Census Asian Voting Age Population VAP", false, 0, 148232));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForTotal("AsianDMV10", "AsianDMV10", "Total Asian licensed Drivers and ID cards over 18yrs old", false, 0, 3005));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForTotalDifference("DifADMV-AVAP", "DifADMV-AVAP", "The Difference between Asian Licensed Drivers and Census Voting Age Population for 2010", false, 0, 3005, 0, 148232));
            return datasetCriteriaList;
        }

        public static ObservableCollection<CriteriaDatasetDTO> AddCriteria_CensusLanguage(ObservableCollection<CriteriaDatasetDTO> datasetCriteriaList)
        {
            // Language
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("SpkOnlyEng", "%SpkOnlyEng", "Percent of ACS people that only speak English Divided by Total Population (2009 5yr Census)", false, 0, 153571, 0, 153570));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("SpkSpanish", "%SpkSpanish", "Percent of ACS people that speak Spanish Divided by Total Population (2009 5yr Census)", false, 0, 153572, 0, 153570));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("SpkOther", "%SpkOther", "Percent of ACS people that speak Other languages besides English and Spanish Divided by Total Population (2009 5yr Census)", false, 0, 153575, 0, 153570));
            return datasetCriteriaList;
        }

        public static ObservableCollection<CriteriaDatasetDTO> AddCriteria_ACSHispanic(ObservableCollection<CriteriaDatasetDTO> datasetCriteriaList)
        {
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForTotal("ACSHispTot", "ACSHispTot", "Total ACS people that are Hispanic", false, 0, 151973));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("ACSMexican", "%ACSMexican", "Percent of ACS Hispanics that are Mexican (2009 5yr Census)", false, 0, 151974, 0, 151973));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("ACSPuerto Rican", "%ACSPuerto Rican", "Percent of ACS Hispanics that are Puerto Rican (2009 5yr Census)", false, 0, 151975, 0, 151973));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("ACSCuban", "%ACSCuban", "Percent of ACS Hispanics that are Cuban (2009 5yr Census)", false, 0, 151976, 0, 151973));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("ACS C.Amer", "%ACS C.Amer", "Percent of ACS Hispanics that are Central American (2009 5yr Census)", false, 0, 151978, 0, 151973));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("ACS S.Amer", "%ACS S.Amer", "Percent of ACS Hispanics that are South American (2009 5yr Census)", false, 0, 151986, 0, 151973));
            return datasetCriteriaList;
        }


        public static ObservableCollection<CriteriaDatasetDTO> AddCriteria_CensusEducation(ObservableCollection<CriteriaDatasetDTO> datasetCriteriaList)
        {
            // Education
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("LessHighSch", "%LessHighSch", "Percent of ACS people that have less than a high school education Divided by Total Population (2009 5yr Census)", false, 0, 153645, 0, 153644));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("HighSchOnly", "%HighSchOnly", "Percent of ACS people that have a high school education Divided by Total Population (2009 5yr Census)", false, 0, 153646, 0, 153644));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("SomeCollege", "%SomeCollege", "Percent of ACS people that have some College education Divided by Total Population (2009 5yr Census)", false, 0, 153647, 0, 153644));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("Bachelor", "%Bachelor", "Percent of ACS people that have Bachelor degree Divided by Total Population (2009 5yr Census)", false, 0, 153648, 0, 153644));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("Graduate", "%Graduate", "Percent of ACS people that have Graduate degree Divided by Total Population (2009 5yr Census)", false, 0, 153649, 0, 153644));
            return datasetCriteriaList;
        }


        public static ObservableCollection<CriteriaDatasetDTO> AddCriteria_CensusIncome(ObservableCollection<CriteriaDatasetDTO> datasetCriteriaList)
        {
            // Income
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("NoIncome", "%NoIncome", "Percent of ACS people that have No Income in past year Divided by Total Population (2009 5yr Census)", false, 0, 153677, 0, 153676));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("SSIncome", "%SSIncome", "Percent of ACS people that have Social Security Income in past year Divided by Total Population (2009 5yr Census)", false, 0, 161266, 0, 161265));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("PublicAsst", "%PublicAsst", "Percent of ACS people that have Public Assistance or Food Stamps Income in past year Divided by Total Population (2009 5yr Census)", false, 0, 161281, 0, 161280));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("Retirement", "%Retirement", "Percent of ACS people that have Retirement Income in past year Divided by Total Population (2009 5yr Census)", false, 0, 161286, 0, 161285));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("Poverty-100", "%Poverty-100", "Percent of ACS people that were below 100% of poverty level Divided by Total Population (2009 5yr Census)", false, 0, 153742, 0, 153741));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("Poverty-100-149", "%Poverty-100-149", "Percent of ACS people that were 100% to 149% of poverty level Divided by Total Population (2009 5yr Census)", false, 0, 153743, 0, 153741));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("Poverty-150+", "%Poverty-150+", "Percent of ACS people that were 150% or above of poverty level Divided by Total Population (2009 5yr Census)", false, 0, 153744, 0, 153741));
            return datasetCriteriaList;
        }


        public static ObservableCollection<CriteriaDatasetDTO> AddCriteria_CensusHousing(ObservableCollection<CriteriaDatasetDTO> datasetCriteriaList)
        {
            // Housing
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForTotal("CensusHseUnts10", "CensusHseUnts10", "Total Census Housing Units", false, 0, 148384));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("LiveHse1yr+", "%LiveHse1yr+", "Percent of ACS people that lived in their house longer than a year Divided by Total Population (2009 5yr Census)", false, 0, 153779, 0, 153763));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("OwnHse", "%OwnHse", "Percent of ACS homes that are Owner Occupied homes Divided by Total Houses (2009 5yr Census)", false, 0, 154174, 0, 154173));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("RentHse", "%RentHse", "Percent of ACS homes that are Renter Occupied homes Divided by Total Houses (2009 5yr Census)", false, 0, 154175, 0, 154173));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("SeasonalHse", "%SeasonalHse", "Percent of ACS homes that have seasonal use Divided by Total Houses (2009 5yr Census)", false, 0, 168758, 0, 154173));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("1detachedHse", "%1detachedHse", "Percent of ACS houses that are 1 unit detached Divided by Total Houses (2009 5yr Census)", false, 0, 169089, 0, 169088));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("1attachedHse", "%1attachedHse", "Percent of ACS houses that are 1 unit attached Divided by Total Houses (2009 5yr Census)", false, 0, 169090, 0, 169088));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("2unitHse", "%2unitHse", "Percent of ACS houses that are 2 units Divided by Total Houses (2009 5yr Census)", false, 0, 169091, 0, 169088));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("3unitHse", "%3unitHse", "Percent of ACS houses that are 3-4 units Divided by Total Houses (2009 5yr Census)", false, 0, 169092, 0, 169088));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("5unitHse", "%5unitHse", "Percent of ACS houses that are 5-9 units Divided by Total Houses (2009 5yr Census)", false, 0, 169093, 0, 169088));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("10unitHse", "%10unitHse", "Percent of ACS houses that are 10-19 units Divided by Total Houses (2009 5yr Census)", false, 0, 169094, 0, 169088));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("20unitHse", "%20unitHse", "Percent of ACS houses that are 20-49 units Divided by Total Houses (2009 5yr Census)", false, 0, 169095, 0, 169088));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("50unit+Hse", "%50unit+Hse", "Percent of ACS houses that are 50 plus units Divided by Total Houses (2009 5yr Census)", false, 0, 169096, 0, 169088));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("MobileHse", "%MobileHse", "Percent of ACS houses that are Mobile Home Divided by Total Houses (2009 5yr Census)", false, 0, 169097, 0, 169088));
            return datasetCriteriaList;
        }

        public static ObservableCollection<CriteriaDatasetDTO> AddCriteria_CensusVeterans(ObservableCollection<CriteriaDatasetDTO> datasetCriteriaList)
        {
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("Veterans", "%Veterans", "Percent of ACS that are Veterans Divided by Total Population (2009 5yr Census)", false, 0, 163262, 0, 163261));
            return datasetCriteriaList;
        }


        public static ObservableCollection<CriteriaDatasetDTO> AddCriteria_CensusTransportation(ObservableCollection<CriteriaDatasetDTO> datasetCriteriaList)
        {
            // Transportation
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("CarDrive", "%CarDrive", "Percent of ACS people that get to work by Car,Truck or Van Divided by Total (2009 5yr Census)", false, 0, 154319, 0, 154318));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("DriveAlone", "%DriveAlone", "Percent of ACS people that Drive Alone to work Divided by Total (2009 5yr Census)", false, 0, 154320, 0, 154318));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("CarPool", "%CarPool", "Percent of ACS people that use a Carpool Divided by Total (2009 5yr Census)", false, 0, 154321, 0, 154318));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("WorkHome", "%WorkHome", "Percent of ACS people that work at home Divided by Total (2009 5yr Census)", false, 0, 154334, 0, 154318));
            return datasetCriteriaList;
        }

        public static ObservableCollection<CriteriaDatasetDTO> AddCriteria_CensusWorkType(ObservableCollection<CriteriaDatasetDTO> datasetCriteriaList)
        {
            // Work Type
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("Management", "%Management", "Percent of ACS people that work in Management Divided by Total (2009 5yr Census)", false, 0, 165290, 0, 165289));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("Service", "%Service", "Percent of ACS people that work in Service Occupations Divided by Total (2009 5yr Census)", false, 0, 165290, 0, 165289));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("Sales", "%Sales", "Percent of ACS people that work in Sales and Office Occupations Divided by Total (2009 5yr Census)", false, 0, 165309, 0, 165289));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("Private", "%Private", "Percent of ACS people that work as Employee of Private Company Divided by Total (2009 5yr Census)", false, 0, 165319, 0, 165289));
            return datasetCriteriaList;
        }

        public static ObservableCollection<CriteriaDatasetDTO> AddCriteria_ElectionsGeneral(ObservableCollection<CriteriaDatasetDTO> datasetCriteriaList)
        {
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForTotal("G10GOV_Tot", "G10GOV_Tot", "Total votes for Governor (2010 General Election)", false, 0, 4030));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("G10GOV_D_Sin", "%G10GOV_D_Sin", "Percent of the total votes that Dem Sink/Smith received for Governor (2010 General Election)", false, 0, 4019, 0, 4030));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("G10GOV_R_Sco", "%G10GOV_R_Sco", "Percent of the total votes that Rep Scott/Carrol received for Governor (2010 General Election)", false, 0, 4020, 0, 4030));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("G10CFO_D_Aus", "%G10CFO_D_Aus", "Percent of the total votes that Dem Ausley received for Chief Finanancial Officer (2010 General Election)", false, 0, 4032, 0, 4043));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("G10CFO_R_Atw", "%G10CFO_R_Atw", "Percent of the total votes that Rep Atwater received for Chief Finanancial Officer (2010 General Election)", false, 0, 4033, 0, 4043));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("G10ATG_D_Gel", "%G10ATG_D_Gel", "Percent of the total votes that Dem Gelber received for Attorney General (2010 General Election)", false, 0, 4045, 0, 4056));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("G10ATG_R_Bon", "%G10ATG_R_Bon", "Percent of the total votes that Rep Atwater received for Attorney General (2010 General Election)", false, 0, 4046, 0, 4056));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("G10AGR_D_Mad", "%G10AGR_D_Mad", "Percent of the total votes that Dem Maddox received for Commissioner of Agriculture (2010 General Election)", false, 0, 4058, 0, 4069));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("G10AGR_R_Put", "%G10AGR_R_Put", "Percent of the total votes that Rep Atwater received for Commissioner of Agriculture (2010 General Election)", false, 0, 4059, 0, 4069));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("G10USS_D_Mee", "%G10USS_D_Mee", "Percent of the total votes that Dem Meek received for US Senate (2010 General Election)", false, 0, 4071, 0, 4082));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("G10USS_R_Rub", "%G10USS_R_Rub", "Percent of the total votes that Rep Rubio received for US Senate (2010 General Election)", false, 0, 4072, 0, 4082));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("G10USS_I_Cri", "%G10USS_I_Cri", "Percent of the total votes that Ind Crist received for US Senate (2010 General Election)", false, 0, 4076, 0, 4082));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForTotal("G08PRE_Tot", "G08PRE_Tot", "Total votes for US President (2008 General Election)", false, 0, 200804020));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("G08PRE_D_Oba", "%G08PRE_D_Oba", "Percent of the total votes that Dem Obama/Biden received for US President (2008 General Election)", false, 0, 200804004, 0, 200804020));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("G08PRE_R_McC", "%G08PRE_R_McC", "Percent of the total votes that Rep McCain/Palin received for US President (2008 General Election)", false, 0, 200804005, 0, 200804020));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForTotal("G06GOV_Tot", "G06GOV_Tot", "Total votes for Governor (2006 General Election)", false, 0, 200604030));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("G06GOV_D_Dav", "%G06GOV_D_Dav", "Percent of the total votes that Dem Davis/Jones received for Governor (2006 General Election)", false, 0, 200604019, 0, 200604030));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("G06GOV_R_Cri", "%G06GOV_R_Cri", "Percent of the total votes that Rep Crist/Kottkamp received for Governor (2006 General Election)", false, 0, 200604020, 0, 200604030));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("G06CFO_D_Sin", "%G06CFO_D_Sin", "Percent of the total votes that Dem Sink received for Chief Finanancial Officer (2006 General Election)", false, 0, 200604032, 0, 200604043));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("G06CFO_R_Lee", "%G06CFO_R_Lee", "Percent of the total votes that Rep Lee received for Chief Finanancial Officer (2006 General Election)", false, 0, 200604033, 0, 200604043));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("G06ATG_D_Cam", "%G06ATG_D_Cam", "Percent of the total votes that Dem Campbell received for Attorney General (2006 General Election)", false, 0, 200604045, 0, 200604056));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("G06ATG_R_McC", "%G06ATG_R_McC", "Percent of the total votes that Rep McCollum received for Attorney General (2006 General Election)", false, 0, 200604046, 0, 200604056));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("G06AGR_D_Cop", "%G06AGR_D_Cop", "Percent of the total votes that Dem Copeland received for Commissioner of Agriculture (2006 General Election)", false, 0, 200604058, 0, 200604069));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("G06AGR_R_Bro", "%G06AGR_R_Bro", "Percent of the total votes that Rep Bronson received for Commissioner of Agriculture (2006 General Election)", false, 0, 200604059, 0, 200604069));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("G06USS_D_Nel", "%G06USS_D_Nel", "Percent of the total votes that Dem Nelson received for US Senate (2006 General Election)", false, 0, 200604071, 0, 200604082));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("G06USS_R_Har", "%G06USS_R_Har", "Percent of the total votes that Rep Harris received for US Senate (2006 General Election)", false, 0, 200604072, 0, 200604082));
            return datasetCriteriaList;
        }

        public static ObservableCollection<CriteriaDatasetDTO> AddCriteria_ElectionsVoterRegistration(ObservableCollection<CriteriaDatasetDTO> datasetCriteriaList)
        {
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForTotal("GENRV10", "GENRV10", "Total registered voters for 2010 General Election", false, 0, 135386));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("GENRVDEM10", "%GENRVDEM10", "Percent of the registered voters that are Democrat for 2010 General Election", false, 0, 135429, 0, 135386));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("GENRVREP10", "%GENRVREP10", "Percent of the registered voters that are Republican for 2010 General Election", false, 0, 135739, 0, 135386));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("GENRVIND10", "%GENRVIND10", "Percent of the registered voters that are not Democrat or Republican for 2010 General Election", false, 0, 135470, 0, 135386));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("GENRVB10", "%GENRVB10", "Percent of the registered voters that are Black for 2010 General Election", false, 0, 135399, 0, 135386));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("GENRVH10", "%GENRVH10", "Percent of the registered voters that are Hispanic for 2010 General Election", false, 0, 135441, 0, 135386));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("GENRVDEMB10", "%GENRVDEMB10", "Percent of the registered Democrats that are Black for 2010 General Election", false, 0, 135401, 0, 135429));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("GENRVREPB10", "%GENRVREPB10", "Percent of the registered Republicans that are Black for 2010 General Election", false, 0, 135419, 0, 135739));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("GENRVINDB10", "%GENRVINDB10", "Percent of the registered voters that are not Democrat or Republican that are Black for 2010 General Election", false, 0, 135410, 0, 135470));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("GENRVBDEM10", "%GENRVBDEM10", "Percent of the registered Blacks that are Democrat for 2010 General Election", false, 0, 135401, 0, 135399));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("GENRVBREP10", "%GENRVBREP10", "Percent of the registered Blacks that are Republicans for 2010 General Election", false, 0, 135419, 0, 135399));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("GENRVBIND10", "%GENRVBIND10", "Percent of the registered Blacks that are not Democrat or Republican for 2010 General Election", false, 0, 135410, 0, 135399));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("GENRVDEMH10", "%GENRVDEMH10", "Percent of the registered Democrats that are Hispanic for 2010 General Election", false, 0, 135443, 0, 135429));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("GENRVREPH10", "%GENRVREPH10", "Percent of the registered Republicans that are Hispanic for 2010 General Election", false, 0, 135461, 0, 135739));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("GENRVINDH10", "%GENRVINDH10", "Percent of the registered voters that are not Democrat or Republican that are Hispanic for 2010 General Election", false, 0, 135452, 0, 135470));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("GENRVHDEM10", "%GENRVHDEM10", "Percent of the registered Hispanics that are Democrat for 2010 General Election", false, 0, 135443, 0, 135441));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("GENRVHREP10", "%GENRVHREP10", "Percent of the registered Hispanics that are Republicans for 2010 General Election", false, 0, 135461, 0, 135441));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("GENRVHIND10", "%GENRVHIND10", "Percent of the registered Hispanics that are not Democrat or Republican for 2010 General Election", false, 0, 135452, 0, 135441));           
            return datasetCriteriaList;
        }

        public static ObservableCollection<CriteriaDatasetDTO> AddCriteria_ElectionsVoted(ObservableCollection<CriteriaDatasetDTO> datasetCriteriaList)
        {
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForTotal("GENVT10", "GENVT10", "Total voters for 2010 General Election", false, 0, 135781));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("GENVTDEM10", "%GENVTDEM10", "Percent voters that are Democrat for 2010 General Election", false, 0, 135817, 0, 135781));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("GENVTREP10", "%GENVTREP10", "Percent voters that are Republican for 2010 General Election", false, 0, 136108, 0, 135781));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("GENVTIND10", "%GENVTIND10", "Percent voters that are not Democrat or Republican for 2010 General Election", false, 0, 135855, 0, 135781));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("GENVTB10", "%GENVTB10", "Percent voters that are Black for 2010 General Election", false, 0, 135788, 0, 135781));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("GENVTH10", "%GENVTH10", "Percent voters that are Hispanic for 2010 General Election", false, 0, 135827, 0, 135781));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("GENVTDEMB10", "%GENVTDEMB10", "Percent Democrat voters that are Black for 2010 General Election", false, 0, 135789, 0, 135817));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("GENVTREPB10", "%GENVTREPB10", "Percent Republican voters that are Black for 2010 General Election", false, 0, 135807, 0, 136108));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("GENVTINDB10", "%GENVTINDB10", "Percent voters that are not Democrat or Republican that are Black for 2010 General Election", false, 0, 135798, 0, 135855));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("GENVTBDEM10", "%GENVTBDEM10", "Percent Black voters that are Democrats for 2010 General Election", false, 0, 135789, 0, 135788));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("GENVTBREP10", "%GENVTBREP10", "Percent Black voters that are Republicans for 2010 General Election", false, 0, 135807, 0, 135788));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("GENVTBIND10", "%GENVTBIND10", "Percent Black voters that are not Democrat or Republican for 2010 General Election", false, 0, 135798, 0, 135788));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("GENVTDEMH10", "%GENVTDEMH10", "Percent Democrat voters that are Hispanic for 2010 General Election", false, 0, 135828, 0, 135817));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("GENVTREPH10", "%GENVTREPH10", "Percent Republican voters that are Hispanic for 2010 General Election", false, 0, 135846, 0, 136108));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("GENVTINDH10", "%GENVTINDH10", "Percent voters that are not Democrat or Republican that are Hispanic for 2010 General Election", false, 0, 135837, 0, 135855));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("GENVTHDEM10", "%GENVTHDEM10", "Percent Hispanic voters that are Democrats for 2010 General Election", false, 0, 135828, 0, 135827));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("GENVTHREP10", "%GENVTHREP10", "Percent Hispanic voters that are Republicans for 2010 General Election", false, 0, 135846, 0, 135827));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("GENVTHIND10", "%GENVTHIND10", "Percent Hispanic voters that are not Democrat or Republican for 2010 General Election", false, 0, 135837, 0, 135827));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("PRIVTDEMB10", "%PRIVTDEMB10", "Percent Democrat voters that are Black for 2010 Primary Election", false, 0, 136924, 0, 136952));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("PRIVTREPB10", "%PRIVTREPB10", "Percent Republican voters that are Black for 2010 Primary Election", false, 0, 136942, 0, 137243));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("PRIVTBDEM10", "%PRIVTBDEM10", "Percent Black voters that are Democrats for 2010 Primary Election", false, 0, 136924, 0, 136923));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("PRIVTBREP10", "%PRIVTBREP10", "Percent Black voters that are Republicans for 2010 Primary Election", false, 0, 136942, 0, 136923));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("PRIVTDEMH10", "%PRIVTDEMH10", "Percent Democrat voters that are Hispanic for 2010 Primary Election", false, 0, 136963, 0, 136952));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("PRIVTREPH10", "%PRIVTREPH10", "Percent Republican voters that are Hispanic for 2010 Primary Election", false, 0, 136981, 0, 137243));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("PRIVTHDEM10", "%PRIVTHDEM10", "Percent Hispanic voters that are Democrats for 2010 Primary Election", false, 0, 136963, 0, 136962));
            datasetCriteriaList.Add(CriteriaDatasetDTO.BuildCriteriaForPercent("PRIVTHREP10", "%PRIVTHREP10", "Percent Hispanic voters that are Republicans for 2010 Primary Election", false, 0, 136981, 0, 136962));
            return datasetCriteriaList;
        }


        //private static ObservableCollection<CriteriaDatasetDTO> GetCriteriaBaseData(ObservableCollection<CriteriaDatasetDTO> criteriaList)
        //{
        //    ObservableCollection<CriteriaDatasetDTO> baseDataCriteria = new ObservableCollection<CriteriaDatasetDTO>();
        //    List<CriteriaDictionaryDTO> baseDataDictionaryIDList = new List<CriteriaDictionaryDTO>();

        //    // build the list of all dictionaryIDs already used as primary criteria in the criteria data set
        //    foreach (var criteria in criteriaList)
        //    {
        //        if (criteria.criteriaType == enumCriteriaType.Total)
        //        {
        //            baseDataDictionaryIDList.AddRange(criteria.dictionaryList);
        //        }
        //    }

        //    // add any dictionaryIDs as a criteria item IF they aren't already there
        //    foreach (var criteria in criteriaList)
        //    {
        //        foreach (var dictionaryItem in criteria.dictionaryList)
        //        {
        //            var dictionaryIDCount = (from dict in baseDataDictionaryIDList
        //                                     where dict.dictionaryID == dictionaryItem.dictionaryID
        //                                         & dict.layerID == dictionaryItem.layerID
        //                                     select dict).Count();
        //            if (dictionaryIDCount == 0)
        //            {
        //                baseDataDictionaryIDList.Add(dictionaryItem);
        //            }
        //        }
        //    }

        //    // Extract the DataDictionaryIDList items in the value list, then add them as a criteria item IF they aren't already there
        //    foreach (var dictionaryItem in baseDataDictionaryIDList)
        //    {
        //        var dictionaryIDCount = (from dict in baseDataDictionaryIDList
        //                                 where dict.dictionaryID == dictionaryItem.dictionaryID
        //                                     & dict.layerID == dictionaryItem.layerID
        //                                 select dict).Count();

        //        // TODO: add dictionaryID names & remove this comment, FYI: dictionaryIDNames are in viewModelBase.regionsDataDictionary
        //        DataDictionaryDTO dictionaryInfo = LayersDataDictionary.GetDictionaryIDInfo(dictionaryItem.layerID, dictionaryItem.dictionaryID);
        //        if (dictionaryInfo == null)
        //        {
        //            dictionaryInfo = new DataDictionaryDTO();
        //            dictionaryInfo.fieldName = dictionaryItem.dictionaryID.ToString();
        //            dictionaryInfo.detailDesc = "Need a description";
        //        }

        //        baseDataCriteria.Add(CriteriaDatasetDTO.BuildCriteriaForTotal(dictionaryInfo.fieldName, dictionaryInfo.fieldName, dictionaryInfo.detailDesc, false, dictionaryItem.layerID, dictionaryItem.dictionaryID));
        //    }


        //    foreach (var newBaseCriteria in baseDataCriteria)
        //    {
        //        criteriaList.Add(newBaseCriteria);
        //    }

        //    return criteriaList;
        //}

        //*********************  Instance  ********************************************



        private List<CriteriaSubscriberInfo> criteriaIDSubscribers = new List<CriteriaSubscriberInfo>();

		/// <summary>
		/// Initializes a new instance of the <see cref="CriteriaDatasetManager"/> class.
		/// Constructor: When the object is created, store a reference to it in the static class.
		/// </summary>
		/// <param name="serviceDAL">The service DAL.</param>
        public CriteriaDatasetManager(ServiceDAL serviceDAL)
        {
            // when the object is created, store a reference to it in the static class
            // That way anything that needs to access the instance methods can do so without passing around references all over the place
            _criteriaDatasetManagerInstance = this;
            _serviceDAL = serviceDAL;
        }

        private void UpdateSubscriber(string subscriberName, ObservableCollection<CriteriaDatasetDTO> datasetCriteriaList)
        {
            var subscriberQuery = from subscriber in criteriaIDSubscribers
                                  where subscriber.subscriberName == subscriberName
                                  select subscriber;
            if (subscriberQuery.Count() == 0)
            {
                // add new subscriber
                CriteriaSubscriberInfo newSubscriber = new CriteriaSubscriberInfo();
                newSubscriber.subscriberName = subscriberName;
                newSubscriber.displayCriteriaIndex = -1;
                newSubscriber.datasetCriteriaList = datasetCriteriaList;
                criteriaIDSubscribers.Add(newSubscriber);
            }
            else
            {
                // replace layer of interest for old subscriber
                CriteriaSubscriberInfo newSubscriber = subscriberQuery.First();
                criteriaIDSubscribers.Remove(newSubscriber);
                newSubscriber.datasetCriteriaList = datasetCriteriaList;
                criteriaIDSubscribers.Add(newSubscriber);
            }
            
        }

        private void UpdateSubscriberDisplayCriteria(string subscriberName, int displayCriteriaIndex)
        {
            //TODO: Replace this with linq as part of code examine for criteria
            for(int ndx=0; ndx < criteriaIDSubscribers.Count(); ndx++)
            {
                if (criteriaIDSubscribers[ndx].subscriberName == subscriberName)
                {
                    if ((displayCriteriaIndex >= 0) & (displayCriteriaIndex < criteriaIDSubscribers[ndx].datasetCriteriaList.Count()))
                    {
                        // don't really see why this wouldn't work, but it doesn't: criteriaIDSubscribers[ndx].displayCriteriaIndex = displayCriteriaIndex;
                        CriteriaSubscriberInfo tmpSubscriber = criteriaIDSubscribers[ndx];
                        tmpSubscriber.displayCriteriaIndex = displayCriteriaIndex;
                        criteriaIDSubscribers[ndx] = tmpSubscriber;
                        
                    }
                }
            }
        }

        private DataDictionaryIDList FindActiveDictionaryIDs()
        {

            List<CriteriaDictionaryDTO> criteriaDictionaryList = new List<CriteriaDictionaryDTO>();

            // build a list of every current data item of interest, along with the layer the data comes from
            
            foreach (var subscriber in criteriaIDSubscribers)
            {
                // NOTE: We're only picking the criteria that are being used for the current display item
                if ( (subscriber.displayCriteriaIndex >= 0)
                   & (subscriber.displayCriteriaIndex < subscriber.datasetCriteriaList.Count()))
                {
                    criteriaDictionaryList.AddRange(subscriber.datasetCriteriaList[subscriber.displayCriteriaIndex].dictionaryList);
                }
                // here we check for any item in their critiera dataset that is providing additional search limitations
                foreach (var criteria in subscriber.datasetCriteriaList)
                {
                    if (criteria.isSelected | criteria.isQueryCriteria)
                    {
                        criteriaDictionaryList.AddRange(criteria.dictionaryList);
                    }
                }
            }

            List<SourceDataSpecificationDTO> sourceDataSpecificationList = CriteriaDataset.GetUniqueSourceDataSpecificationFromCriteriaDictionaryList(criteriaDictionaryList);
            return CriteriaDataset.GetUniqueDictionaryIDListFromSourceDataSpecificationList(sourceDataSpecificationList);
        }


    }
}
